// +---------------------------------------------------------------------
// | 潮州市潮安区东凤镇浅沙软件开发工作室
// +---------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.jacinto.cn All rights reserved.
// +---------------------------------------------------------------------
// | Licensed 浅沙建站系统并不是自由软件，未经许可不能去掉浅沙建站系统相关版权
// +---------------------------------------------------------------------
// | Author: 浅沙软件开发工作室 <qs_jacinto@qq.com>
// +---------------------------------------------------------------------
import {
    Store as VuexStore,
    CommitOptions,
    DispatchOptions,
    Module
  } from 'vuex'
  
  // TODO: How to surpass cyclical dependency linting errors cleanly?
  import { RootState } from '@/store'
  import { state } from './state'
  import { mutations, Mutations } from './mutations'
  import { actions, Actions } from './actions'
  import type { UserState } from './state'
  
  export { UserState }
  
  export type UserStore<S = UserState> = Omit<VuexStore<S>, 'getters' | 'commit' | 'dispatch'>
  & {
    commit<K extends keyof Mutations, P extends Parameters<Mutations[K]>[1]>(
      key: K,
      payload: P,
      options?: CommitOptions
    ): ReturnType<Mutations[K]>
  } & {
    dispatch<K extends keyof Actions>(
      key: K,
      payload: Parameters<Actions[K]>[1],
      options?: DispatchOptions
    ): ReturnType<Actions[K]>
  };
  export const store: Module<UserState, RootState> = {
    state,
    mutations,
    actions
    // TODO: With namespaced option turned on, having problem how to use dispatch with action types...
    // But without it, a bigger store might have clashes in namings
    // namespaced: true,
  }
  